package com.hutianao.gqgl.dictionary.service.impl;

import com.hutianao.gqgl.dictionary.respository.DictionaryDao;
import com.hutianao.gqgl.dictionary.service.DictionaryService;
import com.hutianao.gqgl.mybatis.entity.PtDictionaryEntity;
import com.hutianao.gqgl.mybatis.entity.PtDictionaryI18n;
import com.hutianao.gqgl.mybatis.ztree.ZtreeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryServiceImpl implements DictionaryService {
    @Autowired
    private DictionaryDao dictionaryDao;

    @Override
    public List<ZtreeEntity> queryLeftTree() {
        return dictionaryDao.queryLeftTree();
    }

    @Override
    public PtDictionaryEntity querydictionaryListById(String dictionaryId) {
        return dictionaryDao.queryDictionaryListById(dictionaryId);
    }

    @Override
    public List<PtDictionaryI18n> getI18nByDictionaryId(String dictionaryId) {
        return dictionaryDao.getI18nByDictionaryId(dictionaryId);
    }

    @Override
    public void deleteDictionaryI18nById(String dictId, String languageId) {
        dictionaryDao.deleteDictionaryI18nById(dictId,languageId);
    }

    @Override
    public void saveDictionaryI18n(PtDictionaryI18n ptDictionaryI18n) {
        List<PtDictionaryI18n> list = dictionaryDao.queryDictionaryI18n(ptDictionaryI18n);
        if(list != null && list.size() > 0){
            dictionaryDao.updateDictionaryI18n(ptDictionaryI18n);
        }else {
            dictionaryDao.insertDictionaryI18n(ptDictionaryI18n);
        }
    }

    @Override
    public void addDictionaryInfo(PtDictionaryEntity ptDictionaryEntity) {
        ptDictionaryEntity.setDictId(String.valueOf(System.currentTimeMillis()));
        dictionaryDao.addDictionaryInfo(ptDictionaryEntity);
    }

    @Override
    public void deleteDictionaryInfoByDictionaryId(String dictId) {
        dictionaryDao.deleteDictionaryInfoByDictionaryId(dictId);
    }
//shen
    @Override
    public void updateDictionaryInfo(PtDictionaryEntity ptDictionaryEntity) {
        dictionaryDao.updateDictionaryInfo(ptDictionaryEntity);
    }

}
